<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-yellow" :isBack="true">
			<block class="text-white" slot="content">门店列表</block>
		</cu-custom>
		<view>
			<view v-if="storeList.length > 0" v-for="(store, index) in storeList" :key="index">
				<view :style="'background-size: 100% 100%; z-index: 1;'"
					class="margin-sm shadow bg-white padding-xs relative" @click="toStoreDetail(store.storeid)">
					<view class="w-100 h-100 absolute top0 left0 bg-half"></view>
					<view class="text-white flex">
						<view class="w-75">
							<view class="padding-xs flex justify-between align-baseline text-lg">
								<text class="">{{store.sname}}</text>
							</view>
							<view class="padding-xs flex justify-between align-baseline">
								<text v-if="store.address">地址: {{store.address}}</text>
								<text v-else>地址: 未填写</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="pageInfo.total == 0" class="padding text-center">
				<text>暂无记录</text>
			</view>
		</view>

		<view v-if="storeList.length < pageInfo.total" class="padding flex flex-direction">
			<button @tap="loadMore" class="cu-btn bg-yellow lg">显示更多</button>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				storeList: [],
				pageInfo: {
					current: 1,
					total: 0,
					size: 10
				},
				zjid: undefined,
				zjgsid: undefined,
			};
		},
		onLoad: function(option) {
			if (option.zjid) {
				this.zjid = option.zjid;
			}
			
			if (option.zjgsid) {
				this.zjgsid = option.zjgsid;
			}
			
			
			this.search();
		},
		methods: {
			toStoreDetail: function(storeid) {
				uni.navigateTo({
					url: '/pages/czj/md/detail?storeid=' + storeid
				});
			},
			loadStore: function() {
				let param = {
					current: this.pageInfo.current,
					size: this.pageInfo.size,
				};
				if (this.zjid) {
					param.zjid = this.zjid;
				}
				if (this.zjgsid) {
					param.zjgsid = this.zjgsid;
				}
				this.api("/md/page").send(param).then(res => {
					if (res.astores.records && res.astores.records.length > 0) {
						res.astores.records.forEach(record => {
							this.storeList.push(record);
						});
						this.pageInfo.total = res.astores.total;
					}
				});
			},
			search: function() {
				this.storeList = [];
				this.pageInfo.current = 1;
				this.loadStore();
			},
			loadMore: function() {
				if (this.storeList.length < this.pageInfo.total) {
					this.pageInfo.current++;
					this.loadStore();
				}
			}
		}
	};
</script>

<style>
</style>